import 'package:flutter_blog_manage_study/res/strings.dart';
import 'package:flutter_blog_manage_study/util/toast_util.dart';
import 'package:flutter_blog_manage_study/widget/pull_smart_refresher.dart';
import 'package:get/get_utils/get_utils.dart';
import 'package:pull_to_refresh/pull_to_refresh.dart';

/// * 作者: Tao
/// * 日期: 2024/3/22
/// * 时间: 9:34
/// * 描述: 刷新扩展
class RefreshExtension {

  /// 刷新加载失败
  /// * [refreshController] RefreshController
  /// * [refresh] 加载类型 上拉、下拉
  static onError(RefreshController refreshController, Refresh refresh) {
    if (refresh == Refresh.pull) {
      refreshController.refreshFailed();
    } else if (refresh == Refresh.down) {
      refreshController.loadFailed();
    }
  }


  /// 刷新加载成功
  /// * [refreshController] RefreshController
  /// * [refresh] 加载类型 上拉、下拉
  /// * [over] 是否为最后一页
  static onSuccess(RefreshController refreshController, Refresh refresh, bool over) {
    // 加载成功，重置刷新状态
    if (refresh == Refresh.pull) {
      refreshController.refreshCompleted();
    } else if (refresh == Refresh.down) {
      refreshController.loadComplete();
    }
    // 最后一页了，无更多数据
    if (over) {
      refreshController.loadNoData();
    }
    if (refresh == Refresh.pull) {
      ToastUtil.show(Strings.pointsNotifySuccess.tr);
    }
  }
}
